import mockApi from "@/api/mockApi";
import type {EducationForm} from '@/types/req/educationForm'
import type {EducationQueryForm} from '@/types/req/educationQueryForm'
import type {Education} from '@/types/resp/education'
import type {Response} from '@/types/response'
import type {Result} from '@/types/result'
import type {Page} from "@/types/page";

export default class educationApi {
  static educations: Education[] = [
    {"id":1,"candidateId":3,"candidateName":"张伟","schoolName":"清华大学","degree":30,"startDate":"2008-09-01","endDate":"2012-06-30","createTime":"2024-01-26 22:24:11","modifyTime":"2024-07-25 22:24:11"},
    {"id":2,"candidateId":1,"candidateName":"王强","schoolName":"上海交通大学","degree":40,"startDate":"2010-09-01","endDate":"2013-06-30","createTime":"2024-04-21 22:24:11","modifyTime":"2024-01-21 22:24:11"},
    {"id":3,"candidateId":3,"candidateName":"张伟","schoolName":"北京大学","degree":40,"startDate":"2012-09-01","endDate":"2015-06-30","createTime":"2024-11-12 22:24:11","modifyTime":"2024-06-21 22:24:11"},
    {"id":4,"candidateId":2,"candidateName":"陈静","schoolName":"浙江大学","degree":10,"startDate":"2009-09-01","endDate":"2012-06-30","createTime":"2025-01-04 22:24:11","modifyTime":"2024-12-08 22:24:11"},
    {"id":5,"candidateId":2,"candidateName":"陈静","schoolName":"复旦大学","degree":40,"startDate":"2012-09-01","endDate":"2015-06-30","createTime":"2024-10-02 22:24:11","modifyTime":"2024-06-25 22:24:11"},
    {"id":6,"candidateId":1,"candidateName":"王强","schoolName":"南京大学","degree":50,"startDate":"2013-09-01","endDate":"2018-06-30","createTime":"2024-09-01 22:24:11","modifyTime":"2024-04-25 22:24:11"},
    {"id":7,"candidateId":3,"candidateName":"张伟","schoolName":"中国人民大学","degree":20,"startDate":"2015-09-01","endDate":"2017-06-30","createTime":"2024-03-23 22:24:11","modifyTime":"2024-05-30 22:24:11"}
  ]

  static async save (educationForm: EducationForm): Promise<Result<void>> {
    console.log('educationApi save params', educationForm)
    const response: Response<void> = await mockApi.operateSuccessfully()
    return response.data
  }

  static async find (educationQueryForm: EducationQueryForm): Promise<Result<Page<Education>>> {
    let filteredEducations = educationApi.educations
    if (educationQueryForm.candidateId) {
      filteredEducations = educationApi.educations.filter(education => education.candidateId === educationQueryForm.candidateId);
    }
    const response: Response<Page<object>> = await mockApi.queryPageSuccessfully(filteredEducations)
    return response.data
  }

  static async findById (id: number): Promise<Result<Education>> {
    console.log('educationApi findById id', id)
    let target = {}
    for (const a of educationApi.educations) {
      if (a.id === id) {
        target = a
      }
    }
    const response: Response<Education> = await mockApi.operateSuccessfullyWithData(target)
    return response.data
  }

  static async del (id: number): Promise<Result<void>> {
    console.log('educationApi del id', id)
    const response: Response<void> = await mockApi.operateSuccessfully()
    return response.data
  }
}